/*
 * http://code.google.com/p/simple-lexing-parsers-4-scala/
 * 
 * Copyright (c) 2011, Sanjay Dasgupta
 * See website for details.
 * 
 * The following code is from the extract of Chapter 31 of the book 
 * "Programming in Scala". The extract is published at the link below:
 * http://lamp.epfl.ch/teaching/foundations_of_software/docs/combinator_parsing.pdf
 * All rights of the authors of the code are acknowledged.
 * 
 * This code illustrates the migration of a parser that extends the 
 * Scala API's JavaTokenParsers trait.
 */

package migration

//import scala.util.parsing.combinator._
import slp.JavaTokenParsers

object Arith extends JavaTokenParsers {
  literal("+", "-", "*", "/", "(", ")")
  
  def expr: Parser[Any] = term ~ rep("+" ~ term | "-" ~ term)
  def term: Parser[Any] = factor ~ rep("*" ~ factor | "/" ~ factor)
  def factor: Parser[Any] = (wholeNumber | decimalNumber | floatingPointNumber) | "(" ~ expr ~ ")"
  
  def main(args: Array[String]) {
    println(parseAll(expr, "2 * (3 + 7)"))
  }
}